package com.jxw.launcher;

import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import cn.qqtheme.framework.entity.City;
import cn.qqtheme.framework.entity.County;
import cn.qqtheme.framework.entity.Province;
import cn.qqtheme.framework.picker.DatePicker;
import cn.qqtheme.framework.picker.OptionPicker;
import cn.qqtheme.framework.util.ConvertUtils;
import cn.qqtheme.framework.widget.WheelView;
import com.jxw.launcher.AddressPickTask;
import com.jxw.launcher.util.Factory;
import com.jxw.launcher.util.Logger;
import com.jxw.utils.UserDBUtil;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import me.jessyan.autosize.internal.CancelAdapt;

/* loaded from: classes.dex */
public class GRZXActivity extends BaseActivity implements View.OnClickListener, CancelAdapt {
    public static final String action = "jason.broadcast.action";
    TextView birEdit;
    int camera;
    private View edit;
    TextView gradeEdit;
    private ImageView imageView;
    TextView locEdit;
    int mRequestCode;
    SharedPreferences preference;
    EditText qqEdit;
    private View saveBtn;
    EditText schoolEdit;
    TextView sexEdit;
    EditText userEdit;
    TextView xingzuoEdit;
    private View xqView;
    private View xxView;
    private View zxView;

    /* JADX INFO: Access modifiers changed from: private */
    public void setEditEnable(boolean z) {
        this.userEdit.setEnabled(z);
        this.xingzuoEdit.setEnabled(z);
        this.sexEdit.setEnabled(z);
        this.locEdit.setEnabled(z);
        this.birEdit.setEnabled(z);
        this.schoolEdit.setEnabled(z);
        this.qqEdit.setEnabled(z);
        this.gradeEdit.setEnabled(z);
    }

    private void setData() {
        String string = this.preference.getString("name", "游客");
        String string2 = this.preference.getString("xingzuo", "");
        String string3 = this.preference.getString("sex", "");
        String string4 = this.preference.getString("loc", "");
        String string5 = this.preference.getString("age", "");
        String string6 = this.preference.getString("school", "");
        String string7 = this.preference.getString("qq", "");
        String string8 = this.preference.getString("grade", "");
        this.userEdit.setText(string);
        this.xingzuoEdit.setText(string2);
        this.sexEdit.setText(string3);
        this.locEdit.setText(string4);
        this.birEdit.setText(string5);
        this.schoolEdit.setText(string6);
        this.qqEdit.setText(string7);
        this.gradeEdit.setText(string8);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void saveData() {
        String obj = this.userEdit.getText().toString();
        String charSequence = this.xingzuoEdit.getText().toString();
        String charSequence2 = this.sexEdit.getText().toString();
        String charSequence3 = this.locEdit.getText().toString();
        String charSequence4 = this.birEdit.getText().toString();
        String obj2 = this.schoolEdit.getText().toString();
        String obj3 = this.qqEdit.getText().toString();
        String charSequence5 = this.gradeEdit.getText().toString();
        this.preference.edit().putString("name", obj).putString("xingzuo", charSequence).putString("sex", charSequence2).putString("loc", charSequence3).putString("age", charSequence4).putString("school", obj2).putString("qq", obj3).putString("grade", charSequence5).apply();
        UserDBUtil.keepLastRecord("", charSequence5, !TextUtils.isEmpty(charSequence2) ? 1 : -1, -1, obj, null);
    }

    private void showTypeDialog() {
        final AlertDialog create = new AlertDialog.Builder(this).create();
        View inflate = View.inflate(this, R.layout.dialog_select_photo, null);
        TextView textView = (TextView) inflate.findViewById(R.id.tv_select_camera);
        ((TextView) inflate.findViewById(R.id.tv_select_gallery)).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.GRZXActivity.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                Intent intent = new Intent("android.intent.action.PICK", (Uri) null);
                intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                GRZXActivity.this.startActivityForResult(intent, 1);
                create.dismiss();
            }
        });
        textView.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.GRZXActivity.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                Uri uriForFile;
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                if (Build.VERSION.SDK_INT < 24) {
                    GRZXActivity gRZXActivity = GRZXActivity.this;
                    uriForFile = Uri.fromFile(new File(gRZXActivity.getDiskCacheDir(gRZXActivity), "head.jpg"));
                } else {
                    GRZXActivity gRZXActivity2 = GRZXActivity.this;
                    uriForFile = FileProvider.getUriForFile(gRZXActivity2, "com.jxw.launcher.fileprovider", new File(gRZXActivity2.getDiskCacheDir(gRZXActivity2), "head.jpg"));
                }
                intent.setFlags(3);
                intent.putExtra("output", uriForFile);
                GRZXActivity.this.startActivityForResult(intent, 2);
                create.dismiss();
            }
        });
        if (this.camera == 0) {
            textView.setVisibility(0);
        } else {
            textView.setVisibility(8);
        }
        create.setView(inflate);
        create.show();
    }

    public String getDiskCacheDir(Context context) {
        if ("mounted".equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
            return context.getExternalCacheDir().getPath();
        }
        return context.getCacheDir().getPath();
    }

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        Uri uriForFile;
        Bundle extras;
        Bitmap bitmap;
        if (i != 1) {
            if (i != 2) {
                if (i == 3 && intent != null && (extras = intent.getExtras()) != null && (bitmap = (Bitmap) extras.getParcelable("data")) != null) {
                    setPicToView(bitmap);
                }
            } else if (i2 == -1) {
                if (Build.VERSION.SDK_INT < 24) {
                    uriForFile = Uri.fromFile(new File(getDiskCacheDir(this), "head.jpg"));
                } else {
                    uriForFile = FileProvider.getUriForFile(this, "com.jxw.launcher.fileprovider", new File(getDiskCacheDir(this), "head.jpg"));
                }
                cropPhoto(uriForFile);
            }
        } else if (i2 == -1) {
            cropPhoto(intent.getData());
        }
        super.onActivityResult(i, i2, intent);
    }

    public void cropPhoto(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", 250);
        intent.putExtra("outputY", 250);
        intent.putExtra("return-data", true);
        intent.setFlags(3);
        startActivityForResult(intent, 3);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v8, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r5v0, types: [android.graphics.Bitmap] */
    private void setPicToView(Bitmap bitmap) {
        FileOutputStream fileOutputStream;
        String str = getDiskCacheDir(this) + File.separator + "head.jpg";
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                try {
                    fileOutputStream = new FileOutputStream(str);
                    try {
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
                        if (this.imageView != null) {
                            this.imageView.setBackground(new BitmapDrawable(BitmapFactory.decodeFile(str)));
                        }
                        Intent intent = new Intent(action);
                        ?? r1 = "data";
                        intent.putExtra("data", str);
                        sendBroadcast(intent);
                        fileOutputStream.flush();
                        fileOutputStream.close();
                        fileOutputStream2 = r1;
                    } catch (FileNotFoundException e) {
                        e = e;
                        fileOutputStream2 = fileOutputStream;
                        e.printStackTrace();
                        fileOutputStream2.flush();
                        fileOutputStream2.close();
                        fileOutputStream2 = fileOutputStream2;
                    } catch (Throwable th) {
                        th = th;
                        try {
                            fileOutputStream.flush();
                            fileOutputStream.close();
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                        throw th;
                    }
                } catch (FileNotFoundException e3) {
                    e = e3;
                }
            } catch (Throwable th2) {
                th = th2;
                fileOutputStream = fileOutputStream2;
            }
        } catch (Exception e4) {
            e4.printStackTrace();
        }
    }

    @Override // com.jxw.launcher.BaseActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        if (Factory.lastResume == 0) {
            this.xqView.setVisibility(0);
            this.xxView.setVisibility(4);
        } else if (Factory.lastResume == 1) {
            this.xxView.setVisibility(0);
            this.xqView.setVisibility(4);
        } else {
            this.xxView.setVisibility(4);
            this.xqView.setVisibility(4);
        }
        String str = getDiskCacheDir(this) + File.separator + "head.jpg";
        try {
            if (new File(str).exists()) {
                this.imageView.setBackground(new BitmapDrawable(BitmapFactory.decodeFile(str)));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.jxw.launcher.BaseActivity, android.support.v4.app.FragmentActivity, android.support.v4.app.SupportActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_grzx);
        findViewById(R.id.xq_btn).setOnClickListener(this);
        findViewById(R.id.xx_btn).setOnClickListener(this);
        findViewById(R.id.lnr_btn).setOnClickListener(this);
        this.preference = getSharedPreferences("userInfo", 0);
        this.xqView = findViewById(R.id.xq_cur);
        this.xxView = findViewById(R.id.xx_cur);
        this.userEdit = (EditText) findViewById(R.id.userEdit);
        this.xingzuoEdit = (TextView) findViewById(R.id.xingzuoEdit);
        this.sexEdit = (TextView) findViewById(R.id.sexEdit);
        this.locEdit = (TextView) findViewById(R.id.locEdit);
        this.birEdit = (TextView) findViewById(R.id.birEdit);
        this.schoolEdit = (EditText) findViewById(R.id.schoolEdit);
        this.qqEdit = (EditText) findViewById(R.id.qqEdit);
        this.gradeEdit = (TextView) findViewById(R.id.gradeEdit);
        this.mRequestCode = 0;
        if (Build.VERSION.SDK_INT >= 23) {
            this.camera = checkSelfPermission("android.permission.CAMERA");
            ArrayList arrayList = new ArrayList();
            if (this.camera != 0) {
                this.mRequestCode |= 1;
                arrayList.add("android.permission.CAMERA");
            }
            if (this.mRequestCode > 0) {
                requestPermissions((String[]) arrayList.toArray(new String[arrayList.size()]), 43);
            }
        }
        this.imageView = (ImageView) findViewById(R.id.tuxiang);
        setData();
        this.edit = findViewById(R.id.edit);
        this.saveBtn = findViewById(R.id.saveBtn);
        this.edit.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.GRZXActivity.3
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                GRZXActivity.this.setEditEnable(true);
                GRZXActivity.this.saveBtn.setVisibility(0);
                GRZXActivity.this.edit.setVisibility(8);
            }
        });
        this.saveBtn.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.GRZXActivity.4
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                GRZXActivity.this.setEditEnable(false);
                GRZXActivity.this.saveBtn.setVisibility(8);
                GRZXActivity.this.edit.setVisibility(0);
                GRZXActivity.this.saveData();
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (Factory.lastResume == 0) {
            this.xqView.setVisibility(0);
            this.xxView.setVisibility(4);
        } else if (Factory.lastResume == 1) {
            this.xxView.setVisibility(0);
            this.xqView.setVisibility(4);
        } else {
            this.xxView.setVisibility(4);
            this.xqView.setVisibility(4);
        }
    }

    public void onExit(View view) {
        finish();
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.lnr_btn) {
            Log.e("gwj", "@2222");
            MyApp.getInstance().mBottomBtnOnClickListener.setContext(this);
            MyApp.getInstance().mBottomBtnOnClickListener.onClick(getString(R.string.tag_args_lnr));
            Factory.lastResume = 2;
        } else if (id != R.id.xq_btn) {
            if (id != R.id.xx_btn) {
                return;
            }
            startActivity("com.jxw.launcher", "com.jxw.launcher.ThemeActivity");
            Factory.lastResume = 1;
        } else {
            MyApp.getInstance().mBottomBtnOnClickListener.setContext(this);
            MyApp.getInstance().mBottomBtnOnClickListener.onClick(getString(R.string.tag_args_yrpt));
            Factory.lastResume = 0;
            this.preference.edit().putInt("lastResume", 0).commit();
        }
    }

    private void startActivity(String str, String str2) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(str, str2));
        try {
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void onConstellationPicker(final View view) {
        OptionPicker optionPicker = new OptionPicker(this, new String[]{"水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"});
        optionPicker.setCycleDisable(false);
        optionPicker.setTopBackgroundColor(-1118482);
        optionPicker.setTopHeight(getResources().getDimensionPixelOffset(R.dimen.x24));
        optionPicker.setTopLineColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setTopLineHeight(1);
        optionPicker.setTitleText("请选择星座");
        optionPicker.setTitleTextColor(-6710887);
        optionPicker.setTitleTextSize(getResources().getDimensionPixelOffset(R.dimen.x11));
        optionPicker.setCancelTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setCancelTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setSubmitTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setSubmitTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setTextColor(WheelView.TEXT_COLOR_FOCUS, -6710887);
        WheelView.DividerConfig dividerConfig = new WheelView.DividerConfig();
        dividerConfig.setColor(WheelView.TEXT_COLOR_FOCUS);
        dividerConfig.setAlpha(140);
        dividerConfig.setRatio(0.125f);
        optionPicker.setDividerConfig(dividerConfig);
        optionPicker.setBackgroundColor(-1973791);
        optionPicker.setSelectedIndex(7);
        optionPicker.setCanceledOnTouchOutside(true);
        optionPicker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { // from class: com.jxw.launcher.GRZXActivity.5
            @Override // cn.qqtheme.framework.picker.OptionPicker.OnOptionPickListener
            public void onOptionPicked(int i, String str) {
                Logger logger = Logger.getLogger();
                logger.e("index=" + i + ", item=" + str);
                ((TextView) view).setText(str);
            }
        });
        optionPicker.show();
    }

    public void onAddressPicker(final View view) {
        AddressPickTask addressPickTask = new AddressPickTask(this);
        addressPickTask.setHideProvince(false);
        addressPickTask.setHideCounty(false);
        addressPickTask.setCallback(new AddressPickTask.Callback() { // from class: com.jxw.launcher.GRZXActivity.6
            @Override // com.jxw.launcher.AddressPickTask.Callback
            public void onAddressInitFailed() {
            }

            @Override // cn.qqtheme.framework.picker.AddressPicker.OnAddressPickListener
            public void onAddressPicked(Province province, City city, County county) {
                if (county == null) {
                    Logger logger = Logger.getLogger();
                    logger.e(province.getAreaName() + city.getAreaName());
                    ((TextView) view).setText(province.getAreaName() + city.getAreaName());
                    return;
                }
                Logger logger2 = Logger.getLogger();
                logger2.e(province.getAreaName() + city.getAreaName() + county.getAreaName());
                ((TextView) view).setText(province.getAreaName() + city.getAreaName() + county.getAreaName());
            }
        });
        addressPickTask.execute("广东", "深圳", "宝安");
    }

    public void onYearMonthDayPicker(final View view) {
        Calendar calendar = Calendar.getInstance();
        final DatePicker datePicker = new DatePicker(this);
        datePicker.setCanceledOnTouchOutside(true);
        datePicker.setUseWeight(true);
        datePicker.setTopPadding(ConvertUtils.toPx(this, 10.0f));
        datePicker.setRangeEnd(2119, 12, 31);
        datePicker.setRangeStart(1949, 1, 1);
        datePicker.setSelectedItem(calendar.get(1), calendar.get(2) + 1, calendar.get(5));
        datePicker.setResetWhileWheel(false);
        datePicker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() { // from class: com.jxw.launcher.GRZXActivity.7
            @Override // cn.qqtheme.framework.picker.DatePicker.OnYearMonthDayPickListener
            public void onDatePicked(String str, String str2, String str3) {
                Logger logger = Logger.getLogger();
                logger.e(str + "-" + str2 + "-" + str3);
                ((TextView) view).setText(str + "-" + str2 + "-" + str3);
            }
        });
        datePicker.setOnWheelListener(new DatePicker.OnWheelListener() { // from class: com.jxw.launcher.GRZXActivity.8
            @Override // cn.qqtheme.framework.picker.DatePicker.OnWheelListener
            public void onYearWheeled(int i, String str) {
                DatePicker datePicker2 = datePicker;
                datePicker2.setTitleText(str + "-" + datePicker.getSelectedMonth() + "-" + datePicker.getSelectedDay());
            }

            @Override // cn.qqtheme.framework.picker.DatePicker.OnWheelListener
            public void onMonthWheeled(int i, String str) {
                DatePicker datePicker2 = datePicker;
                datePicker2.setTitleText(datePicker.getSelectedYear() + "-" + str + "-" + datePicker.getSelectedDay());
            }

            @Override // cn.qqtheme.framework.picker.DatePicker.OnWheelListener
            public void onDayWheeled(int i, String str) {
                DatePicker datePicker2 = datePicker;
                datePicker2.setTitleText(datePicker.getSelectedYear() + "-" + datePicker.getSelectedMonth() + "-" + str);
            }
        });
        datePicker.show();
    }

    public void onGradePicker(final View view) {
        OptionPicker optionPicker = new OptionPicker(this, new String[]{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "七年级", "八年级", "九年级", "高一", "高二", "高三"});
        optionPicker.setCycleDisable(true);
        optionPicker.setTopBackgroundColor(-1118482);
        optionPicker.setTopHeight(getResources().getDimensionPixelOffset(R.dimen.x24));
        optionPicker.setTopLineColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setTopLineHeight(1);
        optionPicker.setTitleText("请选择年级");
        optionPicker.setTitleTextColor(-6710887);
        optionPicker.setTitleTextSize(getResources().getDimensionPixelOffset(R.dimen.x11));
        optionPicker.setCancelTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setCancelTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setSubmitTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setSubmitTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setTextColor(WheelView.TEXT_COLOR_FOCUS, -6710887);
        WheelView.DividerConfig dividerConfig = new WheelView.DividerConfig();
        dividerConfig.setColor(WheelView.TEXT_COLOR_FOCUS);
        dividerConfig.setAlpha(140);
        dividerConfig.setRatio(0.125f);
        optionPicker.setDividerConfig(dividerConfig);
        optionPicker.setBackgroundColor(-1973791);
        optionPicker.setSelectedIndex(7);
        optionPicker.setCanceledOnTouchOutside(true);
        optionPicker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { // from class: com.jxw.launcher.GRZXActivity.9
            @Override // cn.qqtheme.framework.picker.OptionPicker.OnOptionPickListener
            public void onOptionPicked(int i, String str) {
                Logger logger = Logger.getLogger();
                logger.e("index=" + i + ", item=" + str);
                ((TextView) view).setText(str);
            }
        });
        optionPicker.show();
    }

    public void onSexPicker(final View view) {
        OptionPicker optionPicker = new OptionPicker(this, new String[]{"男", "女"});
        optionPicker.setCycleDisable(true);
        optionPicker.setTopBackgroundColor(-1118482);
        optionPicker.setTopHeight(getResources().getDimensionPixelOffset(R.dimen.x24));
        optionPicker.setTopLineColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setTopLineHeight(1);
        optionPicker.setTitleText("请选择性别");
        optionPicker.setTitleTextColor(-6710887);
        optionPicker.setTitleTextSize(getResources().getDimensionPixelOffset(R.dimen.x11));
        optionPicker.setCancelTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setCancelTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setSubmitTextColor(WheelView.TEXT_COLOR_FOCUS);
        optionPicker.setSubmitTextSize(getResources().getDimensionPixelOffset(R.dimen.x12));
        optionPicker.setTextColor(WheelView.TEXT_COLOR_FOCUS, -6710887);
        WheelView.DividerConfig dividerConfig = new WheelView.DividerConfig();
        dividerConfig.setColor(WheelView.TEXT_COLOR_FOCUS);
        dividerConfig.setAlpha(140);
        dividerConfig.setRatio(0.125f);
        optionPicker.setDividerConfig(dividerConfig);
        optionPicker.setBackgroundColor(-1973791);
        optionPicker.setSelectedIndex(7);
        optionPicker.setCanceledOnTouchOutside(true);
        optionPicker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { // from class: com.jxw.launcher.GRZXActivity.10
            @Override // cn.qqtheme.framework.picker.OptionPicker.OnOptionPickListener
            public void onOptionPicked(int i, String str) {
                Logger logger = Logger.getLogger();
                logger.e("index=" + i + ", item=" + str);
                ((TextView) view).setText(str);
            }
        });
        optionPicker.show();
    }
}
